import pymysql


def delete(db):
	try:
		sql = 'DELETE FROM %s WHERE A not IN (SELECT dt.mindeptno FROM(SELECT min(A) AS mindeptno FROM data GROUP BY number) dt)' % db
		conn = pymysql.connect(host='localhost', user='root', passwd="*******", db="lottery", port=3306,
		                       charset='utf8')
		cur = conn.cursor()
		cur.execute(sql)
		conn.commit()
		cur.close()
		conn.close()
	except Exception as e:
		with open('db_fail.txt', 'a')as f:
			f.write('%s    %s\n' % (db, e))


if __name__ == '__main__':
	delete('data')
